// 微信异步操作

export const navigateTo = ({url}) => {
    return new Promise((resolve,reject) => {
        // console.log(url);
        wx.navigateTo({
            url: url,
            success: (result)=>{
                resolve(result)
            },
            fail: ()=>{
                reject()
                console.log(1);
            },
            complete: ()=>{}
        });
    })
}

export const switchTab = ({url}) => {
    return new Promise((resolve,reject) => {
        // console.log(url);
        // console.log('switchTab');
        wx.switchTab({
            url: url,
            success: (result)=>{
                resolve(result)
            },
            fail:()=>{
                console.log('swtich fail');
            }

        });
    })
}

export const reLaunch = ({url}) => {
    return new Promise((resolve,reject) => {
        // console.log(url);
        // console.log('switchTab');
        wx.reLaunch({
            url: url,
            success: (result)=>{
                resolve(result)
            },
            fail:()=>{
                console.log('relaunch fail');
            }

        });
    })
}

export const  getUserInfo = ()=>{
    wx.getUserInfo({
        withCredentials: 'false',
        lang: 'zh_CN',
        timeout:5000,
        success: (res)=>{
            resolve(res)
        },
        fail: ()=>{
            console.log('getUserInf fail');
        },
    });
}

export const slectorQuery = (selector)=>{

        return new Promise((resolve) => {
          let selQuery = wx.createSelectorQuery().in(this)       
          selQuery.select(selector).boundingClientRect(res => {
              
              resolve(res)
          }).exec();
        })

}

export const showModal = (data) => {
    return new Promise((resolve,reject) => {
        wx.showModal({
           ...data,
            success: res => {
             return resolve(res)
            }
          })
    })
}
